package com.pan.test.socket.example03;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class MyServer03 {

    public static String PICTURE_DIR_PATH = System.getProperty("user.dir")+"\\picture\\server";

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(11451);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        File file = new File(PICTURE_DIR_PATH+"\\receive.png");
        file.createNewFile();
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write(inputStream.readAllBytes());

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("server 收到图片".getBytes());
        socket.shutdownOutput();

        outputStream.close();
        fileOutputStream.close();
        inputStream.close();
        socket.close();
        serverSocket.close();

    }
}
